<template>
    <a-modal
      centered
      :title="title"
      :width="700"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <j-form-container :disabled="formDisabled">
        <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
          <a-row>
            <a-col :span="24">
              <a-form-model-item label="工程起始时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="projectBeforeTime">
                <j-date placeholder="请选择工程起始时间" v-model="model.projectBeforeTime" :show-time="true"
                        date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="24">
              <a-form-model-item label="工程模板" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="templateId">
                <a-select v-model="model.templateId" placeholder="请选择" default-value="0" style="width: 100%">
                  <a-select-option :value="item.id" v-for="(item,index) in templateTypeOptions" :key="index">
                    {{item.mouldName}}
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </j-form-container>
    </a-spin>

  </a-modal>
</template>

<script>
import { disabledAuthFilter } from "@/utils/authFilter"
import {filterDictTextByCache} from '@comp/dict/JDictSelectUtil'
import {getFileAccessHttpUrl, httpAction, postAction} from '@/api/manage'

export default {
  name: "addProgressLogModal",
  components: {
  },
  data() {
    return {
      model: {},
      title: '',
      visible: false,
      customerId: 0,
      templateTypeOptions:[],
      labelCol: {
        xs: {span: 24},
        sm: {span: 5},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 16},
      },
      confirmLoading: false,
      validatorRules: {
        projectBeforeTime: [{ required: true, message: '工程起始时间不能为空' }],
        templateId: [{ required: true, message: '请选择工程模板' }],
      },
      url: {
        addTemplate: "/ghConstructionMould/addTemplate",
        getTemplateList: "/ghConstructionMould/getTemplateList",
      },
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    this.getTemplateList();
  },
  methods: {
    add(customerId) {
      this.customerId = customerId;
      this.visible = true;
    },
    handleCancel() {
      this.visible = false;
    },
    getTemplateList () {
      postAction(this.url.getTemplateList, {customerId: this.customerId}).then((res) => {
        this.templateTypeOptions = res.result;
      })
    },
    handleOk() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if (!this.model.id) {
            httpurl += this.url.addTemplate;
            method = 'post';
          }
          this.model.customerId = this.customerId;
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message);
              that.$emit('ok',this.model.templateId);
            } else {
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            this.visible = false;
            this.model = {};
          })
        }

      })
    },
  }
}
</script>

<style scoped>
.avatar-uploader > .ant-upload {
  width:104px;
  height:104px;
}
.ant-upload-select-picture-card i {
  font-size: 49px;
  color: #999;
}

.ant-upload-select-picture-card .ant-upload-text {
  margin-top: 8px;
  color: #666;
}

.ant-table-tbody .ant-table-row td{
  padding-top:10px;
  padding-bottom:10px;
}

.drawer-bootom-button {
  position: absolute;
  bottom: 0;
  width: 100%;
  border-top: 1px solid #e8e8e8;
  padding: 10px 16px;
  text-align: right;
  left: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}

/*【JTC-502】 添加用户两个滚动条*/
/deep/ .ant-drawer-body {
  padding-bottom: 53px;
}

</style>
